/*
 * Copyright (c) 2020-2099 the original author or authors. All rights reserve.
 */
package org.tianyun.cloud.dashboard.rabbit;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.UnsupportedEncodingException;

/**
 * 消息消费示例
 *
 * @auther ebert_chan
 */
@Component
public class RabbitConsumerSample {

    private static final Logger LOGGER = LoggerFactory.getLogger(RabbitConsumerSample.class);

    @RabbitListener(bindings = @QueueBinding(value = @Queue(value = "queue.test", durable = "true"), exchange = @Exchange(value = "exchange.test", type = ExchangeTypes.TOPIC), key = "test.*"))
    public void messageConsume(Message message) throws UnsupportedEncodingException {
        LOGGER.info("headers: {}", message.getMessageProperties().getHeaders());
        LOGGER.info("body: {}", new String(message.getBody(), "utf-8"));
    }

}
